import React, {Component} from 'react'
import { Tabs,Form } from 'antd';
import OtherInfo from './OtherInfo';
import ContactInfo from './ContactInfo';
import MainInfo from './MainInfo'
const TabPane = Tabs.TabPane;
const WrappedModalForm = Form.create()(MainInfo);

export default class ListInfo extends React.Component {
    constructor(props) {
        super(props);
        let searchCondition = {custCode: this.props.custCode}
        this.state = {
            isAdd: this.props.isAdd,
            searchCondition: searchCondition,
            mainInfo: this.props.rowObj ? this.props.rowObj:{}
        };
    }

    componentWillReceiveProps(nextProps) {
        let searchCondition = {custCode: nextProps.custCode}
        this.setState({
            isAdd: nextProps.isAdd,
            searchCondition: searchCondition,
            mainInfo: nextProps.rowObj
        });
    }

    render() {
        let tempNode1;
        let tempNode2;
        if(this.props.custCode != "" && this.props.custCode != undefined){
            tempNode1 =
                <TabPane tab="其他信息" key="2">
                    <OtherInfo
                        url = '/base/custother/listByCustCode'
                        searchCondition={this.state.searchCondition}
                    />
                </TabPane>
            tempNode2 =
                <TabPane tab="地址信息" key="3">                    
                    <ContactInfo
                        url = '/base/custcontact/listByCustCode'
                        searchCondition={this.state.searchCondition}
                    />
                </TabPane>
        }else{
            tempNode1 = 
                <TabPane disabled tab="其他信息" key="2">
                    <OtherInfo
                        url = '/base/custother/listByCustCode'
                        searchCondition={this.state.searchCondition}
                    />
                </TabPane>
            tempNode2 =
                <TabPane disabled tab="地址信息" key="3">                    
                    <ContactInfo
                        url = '/base/custcontact/listByCustCode'
                        searchCondition={this.state.searchCondition}
                    />
                </TabPane>
            
        }
        return (
            <Tabs tabPosition="left" defaultActiveKey="1">
                <TabPane tab="主信息" key="1">
                    <WrappedModalForm
                        isAdd={this.state.isAdd} mainInfo={this.state.mainInfo}
                    />
                </TabPane>
                {tempNode1}
                {tempNode2}
            </Tabs>
        );
    }
}
